#include "main.h"
#include <QProcess>

top_menu::top_menu(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::top_menu)
{
    ui->setupUi(this);
    ui->groupBox->hide();
    ui->guide->hide();
    QObject::connect(ui->poweroff,SIGNAL(clicked()),this,SLOT(poweroff()));
    QObject::connect(ui->restart,SIGNAL(clicked()),this,SLOT(resatrt()));
    QObject::connect(ui->reset_application,SIGNAL(clicked()),this,SLOT(reset_application()));
    QObject::connect(ui->guide,SIGNAL(clicked()),this,SLOT(guide()));
    timer=new QTimer();
    QObject:: connect( timer, SIGNAL(timeout()), SLOT(timeDone()) );
    timer->setSingleShot(true);
}

top_menu::~top_menu()
{
    delete ui;
}

void top_menu::timeDone()
{
   ui->groupBox->hide();
}
void top_menu::poweroff()
{
    stop_action();
    action("poweroff","确认是否关机？");
}
void top_menu::resatrt()
{
    stop_action();
    action("reboot","确认是否重启设备？");
}
void top_menu::reset_application()
{
    BUTTON_SOUND;
    if( Affirm("确认是否重启程序？"))
    {
    ::close(pwm->pwm_fd);
    stop_action();
    qApp->quit();
  //  QStringList strlst ;
   // strlst<<"-qws" << "-display VNC:LinuxFb:mmWidth160:mmHeight120:0";
 //  QProcess::startDetached(qApp->applicationFilePath(), strlst);
    }

}

void top_menu::guide()
{

}

void top_menu::action(char* cmd,const char* tips)
{
      BUTTON_SOUND;
      if( Affirm(tips)) system(cmd);

}

 void top_menu::on_menu_toggled()
 {
   timer->start(10000);
 }

 void top_menu::stop_action()
 {
     STOP_ACTION
//     stop_open_front_door
//     stop_close_front_door
//     stop_front_door_Sealing_strip_Inflation
//     stop_front_door_Sealing_strip_Exhaust
//     stop_open_back_door
//     stop_close_back_door
//     stop_back_door_Sealing_strip_Inflation
//     stop_back_door_Sealing_strip_Exhaust
     heating_valve_OFF
 }
